﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace emulib
{
    class MSSQLHandler : IMmoDatabase
    {
        SqlConnection sqlConnect; 
        public Boolean Connect(ServerInfo sinfo)
        {
            sqlConnect = new SqlConnection(
            String.Format("user id={0}; password={1}; server={2}; database={3}; connection timeout=30;",
            sinfo.dbInfo.sqluser, sinfo.dbInfo.sqlpass, sinfo.dbInfo.sqlhost, sinfo.dbInfo.sqldb));
            try
            {
                sqlConnect.Open();
            }
            catch(Exception e)
            {
                Console.WriteLine("Connection error: " + e.Message);
                return false;
            }
            return true;

        }
        public void Disconnect()
        {
            sqlConnect.Close();
        }
        public IDataRecord Select(String what, String from, String where = null, String orderBy = null, Boolean direction = false, Int32 limitStart = -1, Int32 limitMax = -1)
        {
            return new SqlCommand().ExecuteReader();
        }
    }
}
